package com.ruoyi.web.controller.questionBank;

import javax.servlet.http.HttpServletResponse;

import com.ruoyi.common.core.domain.entity.ItemBank;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.system.service.IssueService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.core.page.TableDataInfo;

import javax.annotation.Resource;
import java.util.List;


/**
 * 赵项阳
 *
 * @author DELL
 * @date 2022/6/6 16:00
 */
@RestController
@RequestMapping(value = "/issue/bank")
public class IssueController extends BaseController {

    @Resource
    IssueService issueService;


    /**
     * 查询题库列表
     */
    @PreAuthorize("@ss.hasPermi('question:issue:list')")
    @GetMapping("/list")
    public TableDataInfo list(ItemBank itemBank)
    {
        startPage();
        List<ItemBank> list = issueService.selectItemBankList(itemBank);
        return getDataTable(list);
    }

    /**
     * 导出题库列表
     */
    @PreAuthorize("@ss.hasPermi('question:issue:export')")
    @Log(title = "题库", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ItemBank itemBank)
    {
        List<ItemBank> list = issueService.selectItemBankList(itemBank);
        ExcelUtil<ItemBank> util = new ExcelUtil<>(ItemBank.class);
        util.exportExcel(response, list, "题库数据");
    }

    /**
     * 获取题库详细信息
     */
    @PreAuthorize("@ss.hasPermi('question:issue:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(issueService.selectItemBankById(id));
    }

    /**
     * 新增题库
     */
    @PreAuthorize("@ss.hasPermi('question:issue:add')")
    @Log(title = "题库", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ItemBank itemBank)
    {
        return toAjax(issueService.insertItemBank(itemBank));
    }

    /**
     * 修改题库
     */
    @PreAuthorize("@ss.hasPermi('question:issue:edit')")
    @Log(title = "题库", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ItemBank itemBank)
    {
        return toAjax(issueService.updateItemBank(itemBank));
    }

    /**
     * 删除题库
     */
    @PreAuthorize("@ss.hasPermi('question:issue:remove')")
    @Log(title = "题库", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(issueService.deleteItemBankByIds(ids));
    }



}
